package org.laptech.calculator;

import android.app.Activity;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.laptech.calc.R;

/**
 * @author Lapin R.
 */
public class ExtAdapter extends ArrayAdapter<Pair<String,Integer>>{
    private final Activity context;
    private final Pair<String, Integer>[] data;

    public ExtAdapter(Activity context, int resource, Pair<String, Integer>[] data) {
        super(context, resource, data);
        this.context = context;
        this.data = data;
    }




    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = context.getLayoutInflater();
        View row = inflater.inflate(R.layout.simple_spinner_item,parent,false);

        String value = data[position].first;



        TextView gameText = (TextView) row.findViewById(R.id.spinnersimpleelem);

        gameText.setText(value);

        return row;

    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position,convertView,parent);
    }
    public View getCustomView(int position, View convertView, ViewGroup parent)
    {

        LayoutInflater inflater = context.getLayoutInflater();
        View row = inflater.inflate(R.layout.spinner_layout,parent,false);

        String value = data[position].first;
        int icon = data[position].second;

            ImageView gameIcon = (ImageView) row.findViewById(R.id.gameIcon);
            TextView gameText = (TextView) row.findViewById(R.id.gameName);
            if(icon!=0)
            {
                gameIcon.setImageResource(icon);

            }
            else
            {
                gameIcon.setVisibility(View.GONE);
            }
            gameText.setText(value);

        return row;
    }
}
